package cn.minimelon.api.controller.common;


import cn.minimelon.api.domain.common.AjaxResult;
import cn.minimelon.api.domain.common.SysNotice;
import cn.minimelon.api.domain.common.TableDataInfo;
import cn.minimelon.api.service.common.ISysNoticeService;
import org.noear.solon.annotation.*;

import java.util.List;

/**
 * 公告信息
 *
 * @author ruoyi
 */
@Controller
@Mapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Inject
    ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @Get
    @Mapping("/list")
    public TableDataInfo list(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @Get
    @Mapping(value = "/{noticeId}")
    public AjaxResult getInfo(@Param Long noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @Post
    @Mapping
    public AjaxResult add(SysNotice notice) {
        notice.setCreateBy(getUsername());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @Put
    @Mapping
    public AjaxResult edit(SysNotice notice) {
        notice.setUpdateBy(getUsername());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @Delete
    @Mapping("/{noticeIds}")
    public AjaxResult remove(@Param Long[] noticeIds) {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
